home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex13-6.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  1KB  |  67 lines

  1. // ex13-6.c -- Order of construction of multiple base,
  2. //             virtual base, and member classes
  3.  
  4. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex13-6.c,v 3.0 90/05/15 22:44:45 kgorlen Rel $
  5.  
  6. #include <iostream.h>
  7.  
  8. class X {
  9. public:
  10.     X(const char* s)    { cout << s << ' '; }
  11.     X()                 { cout << "X::X() "; }
  12. };
  13.  
  14. class V: public X {
  15. public:
  16.     V(const char* s = "default"):
  17.         X("V::X")       { cout << s << ' '; }
  18. };
  19.  
  20. class A {
  21.     X a1;
  22.     X a2;
  23. public:
  24.     A(const char* s): a2("A::a2") { cout << s << ' '; }
  25. };
  26.  
  27. class B1: public A, public virtual V {
  28.     X b1;
  29.     X b2;
  30. public:
  31.     B1(const char* s):
  32.         b2("B1::b2"),
  33.         b1("B1::b1"),
  34.         V("B1::V"),
  35.         A("B1::A")      { cout << s << ' '; }
  36. };
  37.  
  38. class B2: public virtual V, public A {
  39.     X b1;
  40.     X b2;
  41. public:
  42.     B2(const char* s):
  43.         b1("B2::b1"),
  44.         b2("B2::b2"),
  45.         A("B2::A"),
  46.         V("B2::V")      { cout << s << ' '; }
  47. };
  48.  
  49. class C: public B1, public B2 {
  50.     int i;
  51.     X c1;
  52.     X c2;
  53. public:
  54.     C(const char* s):
  55.         B2("C::B2"),
  56.         c1("C::c1"),
  57.         i((cout << "C::i ",0)),
  58.         B1("C::B1"),
  59.         V("C::V"),
  60.         c2("C::c2")     { cout << s << endl; }
  61. };
  62.  
  63. main()
  64. {
  65.     C c("c");
  66. }
  67.